package org.ushio.nchu_22201406.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.ushio.common_module.entity.BusinessInformation;
import org.ushio.nchu_22201406.service.BusinessInformationService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@CrossOrigin(origins = "http://localhost:8080")
@RestController
@RequestMapping("/business-information")
public class BusinessInformationController {

    private final BusinessInformationService businessInformationService;

    @Autowired
    public BusinessInformationController(BusinessInformationService businessInformationService) {
        this.businessInformationService = businessInformationService;
    }

    @GetMapping("/by-phone-number")
    public ResponseEntity<BusinessInformation> getBusinessInformationByPhoneNumber(@RequestParam String phoneNumber) {
        BusinessInformation businessInformation = businessInformationService.findBusinessInformationByPhoneNumber(phoneNumber);
        return ResponseEntity.ok(businessInformation);
    }

    @GetMapping("/businessInformation")
    public List<BusinessInformation> getAllBusinessInformation() {
        return businessInformationService.getAllBusinessInformation();
    }
    @GetMapping("/businessInformation/{phoneNumber}")
    public BusinessInformation getBusinessInfoByPhoneNumber(@PathVariable String phoneNumber) {
        return businessInformationService.getBusinessInformationByPhoneNumber(phoneNumber);
    }
    @PutMapping("/businessInformation/{phoneNumber}/updatePackageID")
    public void deletePackageID(@PathVariable String phoneNumber) {
        businessInformationService.updatePackageID(phoneNumber);
    }
}
